/** 校验http协议 */
export const hasProtocol = link => {
  if (link.match(/^http:|https:/) || link.match(/^\/\//)) {
    return true
  }
  return false
}

/**
 * 给指定url添加参数
 * @param paramsMap
 * @param url
 * @returns {string}
 */
export const joinParams = (paramsMap, url) => {
  const keys = Object.keys(paramsMap)
  const params = []
  keys.forEach(item => {
    if (paramsMap[item] !== undefined) {
      params.push(`${item}=${encodeURIComponent(paramsMap[item])}`)
    }
  })
  let prefix = url && url.indexOf('?') >= 0 ? '&' : '?'
  return `${url}${prefix}${params.join('&')}`
}
